package org.qiyu.live.api.controller;

import org.apache.dubbo.config.annotation.DubboReference;
import org.qiyu.live.common.interfaces.vo.WebResponseVO;
import org.qiyu.live.user.dto.UserDTO;
import org.qiyu.live.user.interfaces.IUserRpc;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/user")
public class UserController {

    @DubboReference
    IUserRpc iUserRpc ;

    @GetMapping("/getUserInfo")
    public UserDTO getUserInfo(Long userId){
         return iUserRpc.getByUserId(userId);
    }

    @GetMapping("/updateUserInfo")
    public boolean updateUserInfo(Long userId, String nickName){
        UserDTO userDTO = new UserDTO();
        userDTO.setUserId(userId);
        userDTO.setNickName(nickName);
        return iUserRpc.updateUserInfo(userDTO);
    }

    @GetMapping("/insertUserInfo")
    public boolean insertUserInfo(Long userId){
        UserDTO userDTO = new UserDTO();
        userDTO.setUserId(userId);
        userDTO.setNickName("test");
        userDTO.setSex(1);
        return iUserRpc.insertUserInfo(userDTO);
    }

    @GetMapping("/batchQueryUserInfo")
    public Map<Long, UserDTO> batchQueryUserInfo(String userIdStr){
        return iUserRpc.batchQueryUserInfo(Arrays.stream(userIdStr.split(",")).map(x->Long.valueOf(x)).collect(Collectors.toList()));
    }



}
